#include<bits/stdc++.h>
using namespace std;
const int inf=0x3f3f3f3f;
struct node{
    int d,v,a,s,sl;
};
struct point{
    int cnt;
    vector<int>index;
};
point pi[3005];
int n,m,l,v;
node a[3005];
int p[3005];
set<int>st;
bool cmp(point a,point b){
    return a.cnt<b.cnt;
}
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int T;
    cin>>T;
    while(T--){
        st.clear();
        cin>>n>>m>>l>>v;
        int cnt=0;
        for(int i=1;i<=n;i++){
            cin>>a[i].d>>a[i].v>>a[i].a;
        }
        for(int i=1;i<=m;i++){
            cin>>p[i];
            pi[i].cnt=0;
            for(int j=1;j<=n;j++){
                if(p[i]>=a[j].d){
                    int s=p[i]-a[j].d;
                    int v1=sqrt(a[j].v*a[j].v+2*a[j].a*s);
                    if(v1>=v&&(a[j].a!=0||a[j].v!=v)){
                        pi[i].index.push_back(j);
                        pi[i].cnt++;
                        if(st.find(j)==st.end()){
                            st.insert(j);
                            cnt++;
                        }
                    }
                }
            }
        }
        cout<<cnt<<" ";
        int del=0;
        sort(pi+1,pi+m+1,cmp);
        for(int i=1;i<=m;i++){
            bool f=1;
            for(int j=0;j<cnt;j++){
                if(st.find(pi[i].index[j])!=st.end()){
                    f=0;
                    st.erase(pi[i].index[j]);
                }
            }
            if(f)del++;
        }
        cout<<del<<endl;
    }
    return 0;
}